package org.ourgrid.peer.business.requester;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.ourgrid.common.internal.IResponseTO;
import org.ourgrid.common.internal.RequesterIF;
import org.ourgrid.common.statistics.beans.peer.Peer;
import org.ourgrid.common.statistics.control.WorkerControl;
import org.ourgrid.peer.business.controller.WorkerNotificationController;
import org.ourgrid.peer.request.NotifyWorkerManagementFailureRequestTO;
import org.ourgrid.peer.request.StartPeerRequestTO;
import org.ourgrid.peer.to.LocalWorker;
import org.ourgrid.worker.business.requester.GetMasterPeerRequester;
import org.ourgrid.worker.request.GetMasterPeerRequestTO;

import br.upe.dsc.patdown.control.PDController;

//import br.upe.dsc.patdown.Controller;

public class NotifyWorkerManagementFailureRequester implements RequesterIF<NotifyWorkerManagementFailureRequestTO> {

	public List<IResponseTO> execute(NotifyWorkerManagementFailureRequestTO request) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		// TODO: Provavelmente eu devo inserir o Patdown é aqui. Testar. Não
		// funcionou.
		// Controller patdownlist = Controller.getInstance();
		// if
		// (patdownlist.shouldNotifyFailure(request.getFailedWorkerDeploymentID()))
		// {

		// we can place checking of the failure here! :D
		String userAtServer = request.getFailedWorkerUserAtServer();
		
		System.out.println("HELLO, " + this.getClass().getName() + ".execute() WAS CALLED. DID A WORKER FAILED?");
		System.out.println("OH, YES IT DID, SIR. IT WAS THAT POOR " + userAtServer
				+ " WORKER. WE BETTER HELP HIM OUT.");
		
		
		// String workerUsername = request.getFailedWorkerUserAtServer();
		// String workerAddress = request.getFailedWorkerAddress();
		// WorkerControl wc = WorkerControl.getInstance();
		// wc.findAllActiveWorkers(responses, Peer)

		WorkerNotificationController.getInstance().doNotifyFailure(responses, request.getFailedWorkerDeploymentID(),
				request.getFailedWorkerAddress(), request.getFailedWorkerUserAtServer(),
				request.getFailedWorkerPublicKey());
		// }
		return responses;
	}
}
